import 'package:flutter/material.dart';
import 'package:ledconfig/config/ledconfig.dart';
import 'package:ledconfig/util/AppColors.dart';

import 'my/my.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home:MyHomePage()
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  final pages = [ledconfig(), my()];

  int selectIndex=0;

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
      body: pages[selectIndex],
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: selectIndex,
        selectedItemColor: AppColors.colorAccent,
        unselectedItemColor: AppColors.normal_text_color,
        items: [
          BottomNavigationBarItem(icon: Image.asset('images/ic_led_config_unselect.png',width: 24,height: 24,),activeIcon: Image.asset('images/ic_led_config_selected.png',width: 24,height: 24,),label: '配置'),
          BottomNavigationBarItem(icon: Image.asset('images/ic_my_unselect.png',width: 24,height: 24,),activeIcon:Image.asset('images/ic_my_selected.png',width: 24,height: 24,),label: '我的')
        ],
        onTap:(int index) {
          if(index!=selectIndex){
            selectBottomItem(index);
          }
        }),// This trailing comma makes auto-formatting nicer for build methods.
    );
  }
  void selectBottomItem(int index){
    setState(() {
      selectIndex = index;
    });
  }
}
